package nl.fonfolio.core {
	import nl.fonfolio.controller.Controller;	

	import flash.display.*;

	import nl.fonfolio.model.Model;
	import nl.fonfolio.view.avatar.Avatar;
	import nl.fonfolio.view.Level;
	import nl.fonfolio.view.Panel;
	import nl.fonfolio.view.Profile;
	import nl.fonfolio.view.ProfileProject;
	import nl.fonfolio.view.Menu;
	import nl.fonfolio.view.project.ProjectMovie;
	import nl.fonfolio.view.project.ProjectRating;
	import nl.fonfolio.view.project.ProjectDescription;
	import nl.fonfolio.view.project.ProjectScroll;
	import nl.fonfolio.view.project.ProjectNav;
	import nl.fonfolio.view.Fullscreen;	

	/**
	 * @author Niels
	 */
	public class Fonfolio extends Sprite {
		private var model : Model;
		private var controller : Controller;
		private var level : Level;
		private var menu : Menu;
		public var panel : Panel;
		private var fullscreen : Fullscreen;

		public function Fonfolio() {
			this.startApplication();
		}

		private function startApplication() : void {
			this.stage.align = StageAlign.TOP_LEFT;
			this.stage.scaleMode = StageScaleMode.NO_SCALE;
			
			this.model = new Model();
			this.controller = new Controller(this.model);
			this.level = new Level(this, this.model, this.controller);
			this.menu = new Menu(this);
			this.menu.y = 535;
			
			this.addChild(this.level);
			this.addChild(this.menu);
						
			// TODO loadlevel in controller verwerken
			this.model.loadLevel(2004);
		}

		public function openProfile(id:Number) : void {
			if (this.panel == null){
				this.panel = new Panel(this,this.model, this.controller);
				var profile:Profile = new Profile(this, this.model, this.controller);	
				var profileProject:ProfileProject = new ProfileProject(this, this.model, this.controller);	
				
				this.controller.loadPortfolioHandler(id);
				this.controller.loadProfileProjectHandler(id);
				
				this.addChild(this.panel);
				this.swapChildren(this.panel, this.menu);
				this.panel.addWidget(profile);
				this.panel.addWidget(profileProject);
			} else {
				this.panel.close();	
			}
		}
		
		public function openProject(id:Number) : void {
			//TODO Portfolio inladen
			//trace("FONFOLIO: open project nummer "+id);
			this.fullscreen = new Fullscreen (this, this.model, this.controller)
			var projectMovie:ProjectMovie = new ProjectMovie(this, this.model, this.controller);	
			var projectRating:ProjectRating = new ProjectRating(this, this.model, this.controller);
			var projectDescription:ProjectDescription = new ProjectDescription(this, this.model, this.controller);	
			var projectScroll:ProjectScroll = new ProjectScroll(this, this.model, this.controller);
			var projectNav:ProjectNav = new ProjectNav(this, this.model, this.controller);
			this.addChild(this.fullscreen);
			this.controller.loadProjectHandler(id);

			this.controller.openFullscreenHandler();
			this.fullscreen.addWidgetLeft(projectMovie);
			this.fullscreen.addWidgetLeft(projectRating);
			this.fullscreen.addWidgetLeft(projectScroll);
			this.fullscreen.addWidgetRight(projectDescription);
			this.fullscreen.addWidgetRight(projectNav);
			
			
		}
		
		public function openDashboard() : void {
		}
		
		public function openSearch() : void {
		}
		
		public function openLogin() : void {
			
		}
	}
}
